//
//  UIViewController+TRCategory.m
//  TRNavigationBar
//
//  Created by QuintGao on 2019/10/27.
//  Copyright © 2019 QuintGao. All rights reserved.
//

#import "UIViewController+TRCategory.h"
#import "UIBarButtonItem+TRCategory.h"
#import "UIImage+TRCategory.h"
#import "TRTransitionDelegateHandler.h"

NSString *const TRViewControllerPropertyChangedNotification = @"TRViewControllerPropertyChangedNotification";

@implementation UIViewController (TRCategory)

static char kAssociatedObjectKey_interactivePopDisabled;
- (void)setTr_interactivePopDisabled:(BOOL)tr_interactivePopDisabled {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_interactivePopDisabled, @(tr_interactivePopDisabled), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    [self postPropertyChangeNotification];
}

- (BOOL)tr_interactivePopDisabled {
    return [objc_getAssociatedObject(self, &kAssociatedObjectKey_interactivePopDisabled) boolValue];
}

static char kAssociatedObjectKey_fullScreenPopDisabled;
- (void)setTr_fullScreenPopDisabled:(BOOL)tr_fullScreenPopDisabled {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_fullScreenPopDisabled, @(tr_fullScreenPopDisabled), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    [self postPropertyChangeNotification];
}

- (BOOL)tr_fullScreenPopDisabled {
    return [objc_getAssociatedObject(self, &kAssociatedObjectKey_fullScreenPopDisabled) boolValue];
}

static char kAssociatedObjectKey_maxPopDistance;
- (void)setTr_maxPopDistance:(CGFloat)tr_maxPopDistance {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_maxPopDistance, @(tr_maxPopDistance), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    [self postPropertyChangeNotification];
}

- (CGFloat)tr_maxPopDistance {
    return [objc_getAssociatedObject(self, &kAssociatedObjectKey_maxPopDistance) floatValue];
}

static char kAssociatedObjectKey_navBarAlpha;
- (void)setTr_navBarAlpha:(CGFloat)tr_navBarAlpha {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navBarAlpha, @(tr_navBarAlpha), OBJC_ASSOCIATION_RETAIN_NONATOMIC);

    self.tr_navigationBar.tr_navBarBackgroundAlpha = tr_navBarAlpha;
}

- (CGFloat)tr_navBarAlpha {
    id obj = objc_getAssociatedObject(self, &kAssociatedObjectKey_navBarAlpha);
    return obj ? [obj floatValue] : 1.0f;
}

static char kAssociatedObjectKey_statusBarHidden;
- (void)setTr_statusBarHidden:(BOOL)tr_statusBarHidden {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_statusBarHidden, @(tr_statusBarHidden), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    [self setNeedsStatusBarAppearanceUpdate];
}

- (BOOL)tr_statusBarHidden {
    id hidden = objc_getAssociatedObject(self, &kAssociatedObjectKey_statusBarHidden);
    return (hidden != nil) ? [hidden boolValue] : TRConfigure.statusBarHidden;
}

static char kAssociatedObjectKey_statusBarStyle;
- (void)setTr_statusBarStyle:(UIStatusBarStyle)tr_statusBarStyle {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_statusBarStyle, @(tr_statusBarStyle), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    [self setNeedsStatusBarAppearanceUpdate];
}

- (UIStatusBarStyle)tr_statusBarStyle {
    id style = objc_getAssociatedObject(self, &kAssociatedObjectKey_statusBarStyle);
    return (style != nil) ? [style integerValue] : TRConfigure.statusBarStyle;
}

static char kAssociatedObjectKey_backStyle;
- (void)setTr_backStyle:(TRNavigationBarBackStyle)tr_backStyle {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_backStyle, @(tr_backStyle), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    if (self.navigationController.childViewControllers.count <= 1) return;
    
    if (tr_backStyle != TRNavigationBarBackStyleNone) {
        NSString *imageName = tr_backStyle == TRNavigationBarBackStyleBlack ? @"btn_back_black" : @"btn_back_white";
        
        UIImage *backImage = [UIImage tr_imageNamed:imageName];
        
        if (self.tr_NavBarInit) {
            self.tr_navigationItem.leftBarButtonItem = [UIBarButtonItem tr_itemWithImage:backImage target:self action:@selector(backItemClick:)];
        }
    }
}

- (TRNavigationBarBackStyle)tr_backStyle {
    id style = objc_getAssociatedObject(self, &kAssociatedObjectKey_backStyle);
    return (style != nil) ? [style integerValue] : TRNavigationBarBackStyleNone;
}

static char kAssociatedObjectKey_pushDelegate;
- (void)setTr_pushDelegate:(id<TRViewControllerPushDelegate>)tr_pushDelegate {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_pushDelegate, tr_pushDelegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    [self postPropertyChangeNotification];
}

- (id<TRViewControllerPushDelegate>)tr_pushDelegate {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_pushDelegate);
}

static char kAssociatedObjectKey_popDelegate;
- (void)setTr_popDelegate:(id<TRViewControllerPopDelegate>)tr_popDelegate {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_popDelegate, tr_popDelegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    [self postPropertyChangeNotification];
}

- (id<TRViewControllerPopDelegate>)tr_popDelegate {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_popDelegate);
}

#pragma mark - Private Methods
// 发送属性改变通知
- (void)postPropertyChangeNotification {
    [[NSNotificationCenter defaultCenter] postNotificationName:TRViewControllerPropertyChangedNotification object:@{@"viewController": self}];
}

- (void)backItemClick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

@end

@implementation UIViewController (TRNavigationBar)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSArray <NSString *> *oriSels = @[@"viewDidLoad",
                                          @"viewWillAppear:",
                                          @"viewDidAppear:",
                                          @"viewWillLayoutSubviews"];
        
        [oriSels enumerateObjectsUsingBlock:^(NSString * _Nonnull oriSel, NSUInteger idx, BOOL * _Nonnull stop) {
            tr_swizzled_instanceMethod(self, oriSel, self);
        }];
    });
}

- (void)tr_viewDidLoad {
    // 设置默认导航栏间距
    self.tr_navItemLeftSpace    = TRNavigationBarItemSpace;
    self.tr_navItemRightSpace   = TRNavigationBarItemSpace;
//    [self tr_viewDidLoad];
}

- (void)tr_viewWillAppear:(BOOL)animated {
    if (self.tr_NavBarInit) {
        // 隐藏系统导航栏
        [self.navigationController setNavigationBarHidden:YES];
        
        // 将自定义导航栏放置顶层
        if (self.tr_navigationBar && !self.tr_navigationBar.hidden) {
            [self.view bringSubviewToFront:self.tr_navigationBar];
        }
        // 状态栏是否隐藏
        self.tr_navigationBar.tr_statusBarHidden = self.tr_statusBarHidden;
    }
    
    if (self.tr_navItemLeftSpace == TRNavigationBarItemSpace) {
        self.tr_navItemLeftSpace = TRConfigure.navItemLeftSpace;
    }
    
    if (self.tr_navItemRightSpace == TRNavigationBarItemSpace) {
        self.tr_navItemRightSpace = TRConfigure.navItemRightSpace;
    }
    
    // 重置navItem_space
    [TRConfigure updateConfigure:^(TRNavigationBarConfigure * _Nonnull configure) {
        configure.tr_navItemLeftSpace  = self.tr_navItemLeftSpace;
        configure.tr_navItemRightSpace = self.tr_navItemRightSpace;
    }];
    
    [self tr_viewWillAppear:animated];
}

- (void)tr_viewDidAppear:(BOOL)animated {
    [self postPropertyChangeNotification];

    [self tr_viewDidAppear:animated];
}

- (void)tr_viewWillLayoutSubviews {
    if (self.tr_NavBarInit) {
        [self setupNavBarFrame];
    }
    [self tr_viewWillLayoutSubviews];
}

#pragma mark - 状态栏
- (BOOL)prefersStatusBarHidden {
    return self.tr_statusBarHidden;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return self.tr_statusBarStyle;
}

#pragma mark - 添加自定义导航栏
static char kAssociatedObjectKey_navigationBar;
- (void)setTr_navigationBar:(TRCustomNavigationBar *)tr_navigationBar {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navigationBar, tr_navigationBar, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

    [self setupNavBarAppearance];
    [self setupNavBarFrame];
}

- (TRCustomNavigationBar *)tr_navigationBar {
    TRCustomNavigationBar *navigationBar = objc_getAssociatedObject(self, &kAssociatedObjectKey_navigationBar);
    if (!navigationBar) {
        navigationBar = [[TRCustomNavigationBar alloc] init];
        [self.view addSubview:navigationBar];
        
        self.tr_NavBarInit = YES;
        self.tr_navigationBar = navigationBar;
    }
    return navigationBar;
}

static char kAssociatedObjectKey_navigationItem;
- (void)setTr_navigationItem:(UINavigationItem *)tr_navigationItem {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navigationItem, tr_navigationItem, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    self.tr_navigationBar.items = @[tr_navigationItem];
}

- (UINavigationItem *)tr_navigationItem {
    UINavigationItem *navigationItem = objc_getAssociatedObject(self, &kAssociatedObjectKey_navigationItem);
    if (!navigationItem) {
        navigationItem = [[UINavigationItem alloc] init];
        self.tr_navigationItem = navigationItem;
    }
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navigationItem);
}

static char kAssociatedObjectKey_navbarInit;
- (void)setTr_NavBarInit:(BOOL)tr_NavBarInit {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navbarInit, @(tr_NavBarInit), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (BOOL)tr_NavBarInit {
    return [objc_getAssociatedObject(self, &kAssociatedObjectKey_navbarInit) boolValue];
}

#pragma mark - 常用属性快速设置
static char kAssociatedObjectKey_navBackgroundColor;
- (void)setTr_navBackgroundColor:(UIColor *)tr_navBackgroundColor {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navBackgroundColor, tr_navBackgroundColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    if (tr_navBackgroundColor) {
        [self.tr_navigationBar setBackgroundImage:[UIImage tr_imageWithColor:tr_navBackgroundColor] forBarMetrics:UIBarMetricsDefault];
    }
}

- (UIColor *)tr_navBackgroundColor {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navBackgroundColor);
}

static char kAssociatedObjectKey_navBackgroundImage;
- (void)setTr_navBackgroundImage:(UIImage *)tr_navBackgroundImage {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navBackgroundImage, tr_navBackgroundImage, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    [self.tr_navigationBar setBackgroundImage:tr_navBackgroundImage forBarMetrics:UIBarMetricsDefault];
}

- (UIImage *)tr_navBackgroundImage {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navBackgroundImage);
}

static char kAssociatedObjectKey_navShadowColor;
- (void)setGk_navShadowColor:(UIColor *)tr_navShadowColor {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navShadowColor, tr_navShadowColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    self.tr_navigationBar.shadowImage = [UIImage tr_changeImage:[UIImage tr_imageNamed:@"nav_line"] color:tr_navShadowColor];
}

- (UIColor *)tr_navShadowColor {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navShadowColor);
}

static char kAssociatedObjectKey_navShadowImage;
- (void)setTr_navShadowImage:(UIImage *)tr_navShadowImage {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navShadowImage, tr_navShadowImage, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    self.tr_navigationBar.shadowImage = tr_navShadowImage;
}

- (UIImage *)tr_navShadowImage {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navShadowImage);
}

static char kAssociatedObjectKey_navLineHidden;
- (void)setTr_navLineHidden:(BOOL)tr_navLineHidden {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navLineHidden, @(tr_navLineHidden), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    self.tr_navigationBar.tr_navLineHidden = tr_navLineHidden;
    
    if (@available(iOS 11.0, *)) {
        UIImage *shadowImage = nil;
        if (tr_navLineHidden) {
            shadowImage = [UIImage new];
        }else if (self.tr_navShadowImage) {
            shadowImage = self.tr_navShadowImage;
        }else if (self.tr_navShadowColor) {
            shadowImage = [UIImage tr_changeImage:[UIImage tr_imageNamed:@"nav_line"] color:self.tr_navShadowColor];
        }
        
        self.tr_navigationBar.shadowImage = shadowImage;
    }
    [self.tr_navigationBar layoutSubviews];
}

- (BOOL)tr_navLineHidden {
    return [objc_getAssociatedObject(self, &kAssociatedObjectKey_navLineHidden) boolValue];
}

static char kAssociatedObjectKey_navTitle;
- (void)setTr_navTitle:(NSString *)tr_navTitle {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navTitle, tr_navTitle, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    self.tr_navigationItem.title = tr_navTitle;
}

- (NSString *)tr_navTitle {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navTitle);
}

static char kAssociatedObjectKey_navTitleView;
- (void)setTr_navTitleView:(UIView *)tr_navTitleView {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navTitleView, tr_navTitleView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    self.tr_navigationItem.titleView = tr_navTitleView;
}

- (UIView *)tr_navTitleView {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navTitleView);
}

static char kAssociatedObjectKey_navTitleColor;
- (void)setTr_navTitleColor:(UIColor *)tr_navTitleColor {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navTitleColor, tr_navTitleColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    if (tr_navTitleColor && self.tr_navTitleFont) {
        self.tr_navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: tr_navTitleColor, NSFontAttributeName: self.tr_navTitleFont};
    }
}

- (UIColor *)tr_navTitleColor {
    id objc = objc_getAssociatedObject(self, &kAssociatedObjectKey_navTitleColor);
    return (objc != nil) ? objc : TRConfigure.titleColor;
}

static char kAssociatedObjectKey_navTitleFont;
- (void)setTr_navTitleFont:(UIFont *)tr_navTitleFont {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navTitleFont, tr_navTitleFont, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    if (tr_navTitleFont && self.tr_navTitleColor) {
        self.tr_navigationBar.titleTextAttributes = @{NSFontAttributeName: tr_navTitleFont, NSForegroundColorAttributeName: self.tr_navTitleColor};
    }
}

- (UIFont *)tr_navTitleFont {
    id objc = objc_getAssociatedObject(self, &kAssociatedObjectKey_navTitleFont);
    return (objc != nil) ? objc : TRConfigure.titleFont;
}

static char kAssociatedObjectKey_navLeftBarButtonItem;
- (void)setTr_navLeftBarButtonItem:(UIBarButtonItem *)tr_navLeftBarButtonItem {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navLeftBarButtonItem, tr_navLeftBarButtonItem, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    self.tr_navigationItem.leftBarButtonItem = tr_navLeftBarButtonItem;
}

- (UIBarButtonItem *)tr_navLeftBarButtonItem {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navLeftBarButtonItem);
}

static char kAssociatedObjectKey_navLeftBarButtonItems;
- (void)setTr_navLeftBarButtonItems:(NSArray<UIBarButtonItem *> *)tr_navLeftBarButtonItems {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navLeftBarButtonItems, tr_navLeftBarButtonItems, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    self.tr_navigationItem.leftBarButtonItems = tr_navLeftBarButtonItems;
}

- (NSArray<UIBarButtonItem *> *)tr_navLeftBarButtonItems {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navLeftBarButtonItems);
}

static char kAssociatedObjectKey_navRightBarButtonItem;
- (void)setTr_navRightBarButtonItem:(UIBarButtonItem *)tr_navRightBarButtonItem {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navRightBarButtonItem, tr_navRightBarButtonItem, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    self.tr_navigationItem.rightBarButtonItem = tr_navRightBarButtonItem;
}

- (UIBarButtonItem *)tr_navRightBarButtonItem {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navRightBarButtonItem);
}

static char kAssociatedObjectKey_navRightBarButtonItems;
- (void)setTr_navRightBarButtonItems:(NSArray<UIBarButtonItem *> *)tr_navRightBarButtonItems {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navRightBarButtonItems, tr_navRightBarButtonItems, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    self.tr_navigationItem.rightBarButtonItems = tr_navRightBarButtonItems;
}

- (NSArray<UIBarButtonItem *> *)tr_navRightBarButtonItems {
    return objc_getAssociatedObject(self, &kAssociatedObjectKey_navRightBarButtonItems);
}

static char kAssociatedObjectKey_navItemLeftSpace;
- (void)setTr_navItemLeftSpace:(CGFloat)tr_navItemLeftSpace {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navItemLeftSpace, @(tr_navItemLeftSpace), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    if (tr_navItemLeftSpace == TRNavigationBarItemSpace) return;
    
    [TRConfigure updateConfigure:^(TRNavigationBarConfigure * _Nonnull configure) {
        configure.tr_navItemLeftSpace = tr_navItemLeftSpace;
    }];
}

- (CGFloat)tr_navItemLeftSpace {
    return [objc_getAssociatedObject(self, &kAssociatedObjectKey_navItemLeftSpace) floatValue];
}

static char kAssociatedObjectKey_navItemRightSpace;
- (void)setTr_navItemRightSpace:(CGFloat)tr_navItemRightSpace {
    objc_setAssociatedObject(self, &kAssociatedObjectKey_navItemRightSpace, @(tr_navItemRightSpace), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    if (tr_navItemRightSpace == TRNavigationBarItemSpace) return;
    
    [TRConfigure updateConfigure:^(TRNavigationBarConfigure * _Nonnull configure) {
        configure.tr_navItemRightSpace = tr_navItemRightSpace;
    }];
}

- (CGFloat)tr_navItemRightSpace {
    return [objc_getAssociatedObject(self, &kAssociatedObjectKey_navItemRightSpace) floatValue];
}

#pragma mark - Public Methods
- (void)showNavLine {
    self.tr_navLineHidden = NO;
}

- (void)hideNavLine {
    self.tr_navLineHidden = YES;
}

- (void)refreshNavBarFrame {
    [self setupNavBarFrame];
}

- (UIViewController *)tr_visibleViewControllerIfExist {
    if (self.presentedViewController) {
        return [self.presentedViewController tr_visibleViewControllerIfExist];
    }
    
    if ([self isKindOfClass:[UINavigationController class]]) {
        return [((UINavigationController *)self).visibleViewController tr_visibleViewControllerIfExist];
    }
    
    if ([self isKindOfClass:[UITabBarController class]]) {
        return [((UITabBarController *)self).selectedViewController tr_visibleViewControllerIfExist];
    }
    
    if (self.isViewLoaded && self.view.window) {
        return self;
    }else {
        NSLog(@"找不到可见的控制器，viewController.self = %@，self.view.window = %@", self, self.view.window);
        return nil;
    }
}

#pragma mark - Private Methods
- (void)setupNavBarAppearance {
    // 设置默认背景色
    if (self.tr_navBackgroundColor == nil) {
        self.tr_navBackgroundColor = TRConfigure.backgroundColor;
    }
    
    // 设置默认标题大小及颜色
    if (self.tr_navTitleFont == nil) {
        self.tr_navTitleFont = TRConfigure.titleFont;
    }
    
    if (self.tr_navTitleColor == nil) {
        self.tr_navTitleColor = TRConfigure.titleColor;
    }
    
    // 设置默认返回样式
    if (self.tr_backStyle == TRNavigationBarBackStyleNone) {
        self.tr_backStyle = TRConfigure.backStyle;
    }
}

- (void)setupNavBarFrame {
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat height = [UIScreen mainScreen].bounds.size.height;
    
    CGFloat navBarH = 0.0f;
    if (width > height) { // 横屏
        if (TR_IS_iPad) {
            CGFloat statusBarH = [UIApplication sharedApplication].statusBarFrame.size.height;
            CGFloat navigaBarH = self.navigationController.navigationBar.frame.size.height;
            navBarH = statusBarH + navigaBarH;
        }else if (TR_NOTCHED_SCREEN) {
            navBarH = TR_NAVBAR_HEIGHT;
        }else {
            if (width == 736.0f && height == 414.0f) {  // plus横屏
                navBarH = self.tr_statusBarHidden ? TR_NAVBAR_HEIGHT : TR_STATUSBAR_NAVBAR_HEIGHT;
            }else { // 其他机型横屏
                navBarH = self.tr_statusBarHidden ? 32.0f : 52.0f;
            }
        }
    }else { // 竖屏
        navBarH = self.tr_statusBarHidden ? (TR_SAFEAREA_TOP + TR_NAVBAR_HEIGHT) : TR_STATUSBAR_NAVBAR_HEIGHT;
    }
    self.tr_navigationBar.frame = CGRectMake(0, 0, width, navBarH);
    self.tr_navigationBar.tr_statusBarHidden = self.tr_statusBarHidden;
    [self.tr_navigationBar layoutSubviews];
}

@end
